using System;
using System.Collections;
using System.Collections.Generic; 
using Mahjong.UI;
using Mahjong.Logic;
using UnityEngine;

//分别在两个命名空间里测试，一个测试逻辑一个测试UI

//在Mahjong.Logic命名空间下实现逻辑相关功能
namespace Mahjong.Logic
{
public partial class Manager
    {
        private Player player; // 声明 player 变量
        private Logic logic; // 声明 logic 变量
        private Base baseLogic; // 声明 baseLogic 变量
        private int lastDrawnCard = 0; // 记录上一次出牌的牌
        private int currentPlayerId = 0; // 记录当前出牌玩家的Id
        // 游戏状态枚举
        public enum GameStatus
        {
            Preparing, // 准备阶段
            Drawing,   // 摸牌阶段
            Discarding, // 出牌阶段
            Responding, // 玩家响应阶段
            Ended    // 游戏结束
        }

        private GameStatus currentStatus = GameStatus.Preparing;

        // 逻辑主循环实现
        public void GameLogicLoop()
        {
            InitializeGame();
            while (!logic.CheckGameEnd()) // 循环条件
            {
                switch (currentStatus)
                {
                    case GameStatus.Preparing:
                        // 准备阶段逻辑
                        PreparePhase();
                        break;
                    case GameStatus.Drawing:
                        // 摸牌阶段逻辑
                        DrawPhase();
                        break;
                    case GameStatus.Discarding:
                        // 出牌阶段逻辑
                        DiscardPhase();
                        break;
                    case GameStatus.Responding:
                        // 玩家响应阶段逻辑
                        RespondPhase();
                        break;
                    case GameStatus.Ended:
                        // 游戏结束逻辑
                        EndedPhase();
                        break;
                }
            }
        }

        //准备游戏
        private void PreparePhase()
        {
            logic.PrepareGame();
            currentStatus = GameStatus.Drawing;
            logic.StartDistribute();//发牌
        }

        //摸牌阶段
        private void DrawPhase()
        {
            int currentPlayerId = GetCurrentPlayerId();
            int card = DrawCardForPlayer(currentPlayerId);
            int drawnCard = logic.DrawCardForManager(currentPlayerId);
            logic.UpdateHandCard(currentPlayerId, drawnCard);
            HandleGang(currentPlayerId, drawnCard);//
            HandleHu(currentPlayerId, drawnCard);
            //如果没杠或者胡，则进入出牌阶段
            currentStatus = GameStatus.Discarding;
        }

        //出牌阶段
        private void DiscardPhase()
        {
            int currentPlayerId = GetCurrentPlayerId();
            int discardedCard = RequestPlayerDiscard(currentPlayerId);/*读取玩家选择的牌*/
            int lastDrawnCard=discardedCard;//记录或者更新这张牌
            /*把这张牌举起*/
            //检查其他玩家是否有响应，如果有，则同时在每个玩家的对应区域显示，但是按优先级进行请求响应操作
            List<string> respondingPlayers = logic.CheckOtherPlayersOperations(currentPlayerId, discardedCard); 
            if (respondingPlayers.Count > 0)
            {
                currentStatus = GameStatus.Responding;//如果有响应，进入响应阶段
            }
            else//无响应，直接出牌并存储
            {
                logic.SetDiscardCard(currentPlayerId, discardedCard);
                currentStatus = GameStatus.Drawing;//如果没响应，进入摸牌阶段
            }
        }

        //玩家响应阶段(请求可响应玩家的响应，根据优先级处理响应操作)
        private void RespondPhase()
        {
            int currentPlayerId = GetCurrentPlayerId();
            int discardedCard = lastDrawnCard;
            List<int> respondingPlayers = logic.CheckOtherPlayersResponse(currentPlayerId, discardedCard);
            if (respondingPlayers.Count > 0)
            {
                // 按优先级排序响应玩家
                List<int> sortedPlayers = SortByPriority(respondingPlayers);
                bool responseHandled = false;//判定是否有执行操作
                /*如果执行吃碰操作，进入对应玩家的出牌阶段
                如果执行杠操作，对应玩家从牌尾摸一张牌后进入出牌阶段
                如果执行胡操作，进入结束阶段
                如果不执行操作，进入下一位玩家的摸牌阶段
                */
                foreach (int player in sortedPlayers)
                {
                    // 获取当前(最优先)响应玩家的操作
                    string responseOperation = GetPlayerResponse(player, discardedCard);

                    if (!string.IsNullOrEmpty(responseOperation))/*如果玩家有响应操作*/
                    {
                        // 根据操作类型处理响应
                        HandlePlayerResponse(player, responseOperation, discardedCard);
                        responseHandled = true;
                        break; // 仅处理最高优先级的响应
                    }
                }

                if (!responseHandled)
                {
                    // 如果所有响应玩家都未执行操作，更新弃牌区
                    logic.SetDiscardCard(currentPlayerId, discardedCard);
                }
            }
            else
            {
                // 没有玩家能够响应，直接更新弃牌区
               logic.SetDiscardCard(currentPlayerId, discardedCard);
               currentStatus = GameStatus.Drawing;//切换回摸牌阶段
            }
            // if (respondingPlayers.Count > 0)
            // {
            //     int priorityPlayer = logic.DeterminePriorityPlayer(respondingPlayers);
            //     logic.HandlePlayerResponse(priorityPlayer, lastDrawnCard);
            //     logic.CheckHuAndGang(priorityPlayer, lastDrawnCard);
            // }
            yield return null;

        }

        private void EndedPhase()
        {
            // 检查游戏是否满足结束条件
            if (logic.CheckGameEnd())
            {
                 currentStatus = GameStatus.Ended;//切换到结束阶段
                // 计算最终得分
                logic.CalculateFinalScores();
                // 获取最终得分和获胜玩家信息
                Dictionary<int, int> finalScores = logic.GetFinalScores();
                int winningPlayer = logic.GetWinningPlayer();
                // 清理资源和重置游戏数据
                ResetGameData();
                /* 如果需要，准备新一轮游戏*/
            }
            else
            {
                // 如果游戏未结束，回到准备阶段或继续游戏
                currentStatus = GameStatus.Preparing;
            }
        }
        
          // 初始化游戏
        public void InitializeGame()
        {
            logic = new Logic(); 
            player = new Player();
            baseLogic = new Base();
            player.CreatePlayerObjects(logic.GetPlayerCount());//创建玩家对象
            ResetGameData();//重置游戏数据
            logic.SetManager(this);//建立manager和logic的双向联系
            logic.PrepareGame();//创建牌堆、移除金、洗牌
        }

        //处理玩家响应
        private void HandlePlayerResponse(int playerId, string operation, int card)
        {
            logic.ProcessPlayerOperation(playerId, operation, card);
        }

        // 按优先级排序响应玩家
        private List<int> SortByPriority(List<int> players)
        {
            // 实现按优先级排序的逻辑，例如胡 > 杠 > 碰 > 吃
            // 可以根据玩家的响应类型和游戏规则进行排序
            return players;
        }

        // 获取玩家对特定牌的响应操作
        private string GetPlayerResponse(int playerId, int card)
        {
            player.GetOperationOptions( availableOperations, currentPlayerId,(selectedOperation) =>
        {
            Debug.Log("玩家选择了: " + selectedOperation);
            // 根据选择执行相应的逻辑
        });
            return null; // 示例返回值
        }


        // 重置游戏数据
        public void ResetGameData()
        {
            Console.WriteLine("Resetting game data.");
            logic.ResetGameData();
            currentStatus = GameStatus.Preparing;
        }
        
        //提供当前玩家Id
        public int GetCurrentPlayerId()
        {
            return currentPlayerId;
        }

        //玩家摸牌
        private int DrawCardForPlayer(int playerId)
        {
            //从牌堆中抽取一张牌
            int card = logic.DrawCardForManager(playerId);
            //更新玩家手牌
            List<int> handCards = logic.GetHandCards(playerId);
            handCards.Add(card);
            logic.UpdateHandCard(playerId, handCards);
            //返回摸到的牌
            return card;
        }

        // 请求玩家出牌
        private int RequestPlayerDiscard(int playerId)
        {
            // 获取玩家手牌
            List<int> handCards = logic.GetHandCards(playerId);
            /*显示手牌界面并请求玩家选择出牌
            manager.UpdatePlayerHandScene(playerId, handCards);*///这部分要在UI中实现

            int selectedCard = ShowDiscardToSelector(handCards);
            // 移除选中的牌
            handCards.Remove(selectedCard);
            // 更新玩家手牌
            logic.UpdateHandCard(playerId, handCards);
            // 返回选中的牌
            return selectedCard;
        }

        //在回调中处理玩家选择的牌
        // public void ShowDiscardToSelector(List<int> handCards, Action<int> callback)
        // {
        //     /* 更新手牌界面，此操作要在UI中实现*/
        //     manager.UpdatePlayerHandScene(currentPlayerId, handCards);
            
        //     /* 设置手牌点击回调 要多经过player中转一次*/
        //     playerUI.SetCardClickedCallback((selectedCard) =>
        //     {
        //         callback(selectedCard);
        //     });
        // }

       

        // 确定优先级最高的玩家
        private int DeterminePriorityPlayer(List<int> players)
        {
            // 实现确定优先级逻辑
            return 0; // 示例返回值
        }

        // 处理玩家响应
        private void HandlePlayerResponse(int playerId, int card)
        {
            // 实现处理玩家响应的逻辑
        }
        //玩家点击出牌的响应
        private void HandlePlayerDiscard(int playerId)
        {
            List<int> handCards = logic.GetHandCards(playerId);
            ShowDiscardToSelector(handCards, (selectedCard) =>
            {
                // 处理玩家选择的牌
                logic.DiscardCard(playerId, selectedCard);
            });
        }

        // 处理游戏结束
        private void HandleGameEnd()
        {
            // 实现游戏结束处理逻辑
        }

              //处理杠牌操作
        public void HandleGang(int playerId, int card)
        {
            Data.GangTypeEnum? gangType = logic.CanGang(playerId, card);
            if (gangType.HasValue)
            {
                logic.GangCard(playerId, card, gangType.Value);
            }
            else
            {
                Console.WriteLine("无法进行杠牌操作");
            }
        }
         //处理吃牌操作
        public void HandleChi(int playerId, int card)
        {
            List<List<int>> availableChiCombinations = logic.CanChi(playerId, card);
            if (availableChiCombinations.Count == 0)
            {
                Console.WriteLine("无法进行吃牌操作");
                return;
            }

            if (availableChiCombinations.Count > 1)
            {
                // 多个选择，显示选择界面
                Manager.ShowChiSelection(availableChiCombinations, (selectedPair) =>
                {
                    logic.ChiCard(playerId, card, selectedPair);
                });
            }
            else
            {
                // 单个选择，直接执行
                logic.ChiCard(playerId, card, availableChiCombinations[0]);
            }
        }
        //碰牌操作
        public void HandlePeng(int playerId, int card)
        {
            if (logic.CanPeng(playerId, card))
            {
                logic.PengCard(playerId, card);
            }
            else
            {
                Console.WriteLine("无法进行碰牌操作");
            }
        }
        //胡牌操作
         public void HandleHu(int playerId, int card)
    {
        List<int> handCards = logic.GetHandCards(playerId);
        handCards.Add(card); // 加上刚摸到的牌

        // 首先调用 CheckStandardHu 进行标准胡牌判断
        if (logic.CheckStandardHu(handCards))
        {
            // 如果标准胡牌成立，显示胡牌选项给玩家
            ShowOperationSelection(playerId, "胡牌");
        }
        else
        {
            // 如果标准胡牌不成立，调用 IsHuPossible 进行万能牌替代判断
            if (logic.IsHuPossible(handCards, card))
            {
                // 如果万能牌替代后可以胡牌，显示胡牌选项给玩家
                ShowOperationSelection(playerId, "胡牌");
            }
            else
            {
                // 不能胡牌，继续游戏流程
                Console.WriteLine("无法胡牌，继续游戏流程");
            }
        }

    }
}

}

namespace Mahjong.UI
{
public class Manager:MonoBehaviour
{
    private Player player;
    private Base baseLogic;
    private Mahjong.Logic.Logic logic;
    private GameStatus currentStatus = GameStatus.Preparing;
    private int currentPlayerId = 0; // 初始为庄家
    private int lastDrawnCard = 0; // 记录上一次摸到的牌

    public enum GameStatus//游戏状态
    {
        Preparing,  // 准备阶段
        Drawing,    // 摸牌阶段
        Discarding, // 出牌阶段
        Responding, // 玩家响应阶段
        Ended       // 游戏结束
    }
    
    

    //开始游戏
    void StartGame()
    {
        InitializeGame(new Dictionary<int, string>());
        StartCoroutine(GameUILoop());//启动
    }

    // 在UI层面初始化游戏
    public void InitializeGame(Dictionary<int, string> playerInfo)
    {
        logic = new Mahjong.Logic.Logic(); 
        player = new Player();
        baseLogic = new Base();
        player.CreatePlayerObjects(logic.GetPlayerCount());
        ResetGameData();
        logic.SetManager(this);/*建立manager和logic的双向联系*/
        logic.PrepareGame();
        baseLogic.LoadLobbySceneRequested();//请求加载大厅界面
    }
    // UI主循环
    private IEnumerator GameUILoop()
    {
        while (true)
        {
            switch (currentStatus)
            {
                case GameStatus.Preparing:
                    // 准备阶段逻辑
                    //等待操作完成后进行下一步
                    yield return PreparePhase();
                    break;
                case GameStatus.Drawing:
                    // 摸牌阶段逻辑
                    yield return DrawPhase();
                    break;
                case GameStatus.Discarding:
                    // 出牌阶段逻辑
                    yield return DiscardPhase();
                    break;
                case GameStatus.Responding:
                    // 玩家响应阶段逻辑
                    yield return RespondPhase();
                    break;
                case GameStatus.Ended:
                    // 游戏结束逻辑
                    yield return EndedPhase();
                    break;
            }
        }
    }

    // 准备阶段
    private IEnumerator PreparePhase()
    {
        // 等待大厅界面加载完成
        yield return new WaitUntil(() => baseLogic.OnLobbySceneLoaded());
        Debug.Log("the currentStatus is " + currentStatus); 
        currentStatus = GameStatus.Drawing;
        Debug.Log("the updated currentStatus is " + currentStatus); 
    }

    // 摸牌阶段
    private IEnumerator DrawPhase()
    {
        int currentPlayerId = GetCurrentPlayerId();
        // 调用逻辑层获取摸到的牌
        int card = logic.DrawCardForManager(currentPlayerId);
        // 更新手牌界面
        UpdatePlayerHandScene(currentPlayerId, logic.GetHandCards(currentPlayerId));
        /*播放摸牌动画，暂时没设计*/
        PlayDrawCardAnimation(currentPlayerId, card);
        // 等待动画完成
        yield return new WaitForSeconds(1f);
        Debug.Log("the currentStatus is " + currentStatus); 
        currentStatus = GameStatus.Discarding;//切换到出牌阶段
        Debug.Log("the updated currentStatus is " + currentStatus); 
    }

    // 出牌阶段
    private IEnumerator DiscardPhase()
    {
        int currentPlayerId = GetCurrentPlayerId();
        //请求当前玩家出牌,存储出牌信息
        int discardedCard = ShowDiscardToSelector(logic.GetHandCards(currentPlayerId));
        lastDrawnCard = discardedCard;
        // 更新弃牌界面
        UpdatePlayerDiscardScene(currentPlayerId, logic.GetDiscardCardsForManager(currentPlayerId));
        // 通知逻辑层处理出牌
        logic.ProcessPlayerOperation(currentPlayerId, "discard", discardedCard);
        // 等待逻辑层响应
        yield return new WaitUntil(() => logic.IsOperationProcessed());
        Debug.Log("the currentStatus is " + currentStatus); 
        // 根据逻辑层返回的状态更新游戏阶段
        currentStatus = ConvertToManagerGameStatus(logic.GetNextStatus());
        Debug.Log("the updated currentStatus is " + currentStatus); 
    }

    // 玩家响应阶段
    private IEnumerator RespondPhase()
    {
        // 等待逻辑层处理响应
        yield return new WaitUntil(() => logic.IsRespondingComplete());
        // 根据逻辑层返回的状态更新游戏阶段
        Debug.Log("the currentStatus is " + currentStatus); 
        currentStatus = ConvertToManagerGameStatus(logic.GetNextStatus());
        Debug.Log("the updated currentStatus is " + currentStatus); 
    }

    // 游戏结束阶段
    private IEnumerator EndedPhase()
    {
        // 显示游戏结束界面
        ShowGameEndScene(logic.GetFinalScores());
        // 等待玩家点击继续或退出
        yield return new WaitUntil(() => IsPlayerReadyForNextAction());
        // 重置游戏数据
        ResetGameData();
        Debug.Log("the currentStatus is " + currentStatus); 
        currentStatus = GameStatus.Preparing;
        Debug.Log("the updated currentStatus is " + currentStatus); 
    }

    // 获取当前玩家Id
    public int GetCurrentPlayerId()
    {
        return currentPlayerId;
    }
    //对游戏状态做类型转换
     private GameStatus ConvertToManagerGameStatus(Mahjong.Logic.Logic.GameStatus logicStatus)
    {
        switch (logicStatus)
        {
            case Mahjong.Logic.Logic.GameStatus.Preparing:
                return GameStatus.Preparing;
            case Mahjong.Logic.Logic.GameStatus.Drawing:
                return GameStatus.Drawing;
            case Mahjong.Logic.Logic.GameStatus.Discarding:
                return GameStatus.Discarding;
            case Mahjong.Logic.Logic.GameStatus.Responding:
                return GameStatus.Responding;
            case Mahjong.Logic.Logic.GameStatus.Ended:
                return GameStatus.Ended;
            default:
                throw new ArgumentOutOfRangeException(nameof(logicStatus), logicStatus, null);
        }
    }

    // 播放摸牌动画
    private void PlayDrawCardAnimation(int playerId, int card)
    {
        // 实现摸牌动画的资源调用和播放逻辑
    }

    // 显示出牌选择界面
    private int ShowDiscardToSelector(List<int> handCards)
    {
        // 实现出牌选择界面的资源调用和玩家选择逻辑
        return 0; // 返回玩家选择的牌
    }

    // 更新玩家手牌界面
    public void UpdatePlayerHandScene(int playerId, List<int> handCards)
    {
        PlayerUI ui = GetPlayerUI(playerId);
        if (ui != null)
        {
            ui.UpdateHandScene(playerId, handCards);
        }
    }

    // 更新玩家弃牌界面
    public void UpdatePlayerDiscardScene(int playerId, List<int> discardCards)    
    {
        PlayerUI ui = GetPlayerUI(playerId);
        if (ui != null)
        {
            ui.UpdateDiscardScene(playerId, discardCards);
        }
    }

    // 显示游戏结束界面
    private void ShowGameEndScene(Dictionary<int, int> finalScores)
    {
        // 实现游戏结束界面的资源调用和显示逻辑
    }

    // 检查玩家是否准备好进行下一步操作
    private bool IsPlayerReadyForNextAction()
    {
        // 实现检查玩家是否点击继续或退出的逻辑
        return false;
    }

    // 重置游戏数据
    public void ResetGameData()
    {
        logic.ResetGameData();
        currentPlayerId = 0;
    }

    // 获取玩家 UI
    private PlayerUI GetPlayerUI(int playerId)
    {
        return player.GetPlayerUI(playerId);
    }

    // 请求加载游戏大厅场景
    public void RequestLobbySceneLoad()
    {
        baseLogic.LoadLobbySceneRequested();
    }
    



    //切换下一个玩家出牌回合
    public int SwitchTurn()
    {
        return currentPlayerId ;
    }

      // 更新Player和data中的手牌
    public void UpdatePlayerHandCards(int playerId, List<int> handCards)
    {
        player.UpdateHandcard(playerId, handCards);
        //通过Logic更新Data中的手牌数据
        logic.UpdateHandCard(playerId, handCards);
    }

    //获取举起牌信息并传递
    public bool GetPlayerRaiseStatus(int playerId)
    {
    Player currentPlayer = player.GetPlayer(playerId);
    if (currentPlayer != null)
    {
        return currentPlayer.IsCardRaised(playerId);
    }
    return false;
    }


    //更新手牌界面
    public void UpdatePlayerHandScene(int playerId, List<int> handCards)
    {
        PlayerUI ui = GetPlayerUI(playerId);
        if (ui != null)
        {
            ui.UpdateHandScene(playerId, handCards);
        }
    }
    //更新弃牌界面
    public void UpdatePlayerDiscardScene(int playerId, List<int> discardCards)    
    {
        PlayerUI ui = GetPlayerUI(playerId);
        if (ui != null)
        {
            ui.UpdateDiscardScene(playerId, discardCards);
        }
    }

    //获取弃牌列表并移除一张弃牌
    public void RemoveDiscardCard(int playerId,int card)
    {
        List<int> discardCard=player.GetDiscardCard(playerId);
        if(discardCard.Contains(card))
        {
            discardCard.Remove(card);
            player.UpdateDiscard(playerId, discardCard);//更新弃牌数量
        }
    }
    
    //显示吃牌给玩家做选择
    public void ShowChiSelection(List<List<int>> options, Action<List<int>> callback)
    {
        //参数使用List<List<int>>表示多个吃牌组合（如[[1,2,3],[2,3,4]]）
        //获取当前玩家ID
        int currentPlayerId=GetCurrentPlayerId();
        //根据ID获取玩家对象
        Player currentPlayer=player.GetPlayer(currentPlayerId);
        if(currentPlayer!=null)
        {   //处理回调函数，返回包装后的回调函数
            Action<List<int>> warppedCallback=selected=>
            {
                if(selected!=null||selected.Count>0)
                {
                    Console.WriteLine("玩家取消选择或选择为空");
                }
                callback(selected);
            };
            //最终调用吃牌UI
            currentPlayer.ShowChiToUi(currentPlayerId,options,warppedCallback);
        }
    }


    //显示碰牌给玩家做选择
    public void ShowPengSelection(List<List<int>> options, Action<List<int>> callback)
    {
        //获取当前玩家ID
        int currentPlayerId=GetCurrentPlayerId();
        //根据ID获取玩家对象
        {   //处理回调函数，返回包装后的回调函数
            Action<List<int>> warppedCallback=selected=>
            {
                if(selected!=null||selected.Count>0)
                {
                    Console.WriteLine("玩家取消选择或选择为空");
                }
                callback(selected);
            };
            //最终调用碰牌UI
            player.GetPlayer(currentPlayerId).ShowPengToUi(currentPlayerId,options,warppedCallback);
        }
    }

    
    //显示杠牌给玩家做选择
     public void ShowGangSelection(List<List<int>> options, Action<List<int>> callback)
    {
        //获取当前玩家ID
        int currentPlayerId=GetCurrentPlayerId();
        //根据ID获取玩家对象
        {   //处理回调函数，返回包装后的回调函数
            Action<List<int>> warppedCallback=selected=>
            {
                if(selected!=null||selected.Count>0)
                {
                    Console.WriteLine("玩家取消选择或选择为空");
                }
                callback(selected);
            };
            //最终调用杠牌UI
            player.GetPlayer(currentPlayerId).ShowGangToUi(currentPlayerId,options,warppedCallback);
        }
    }
    //显示胡牌给玩家做选择
    public void ShowHuSelection(List<List<int>> options,Action<List<int>> callback)
       {
           //获取当前玩家ID
           int currentPlayerId=GetCurrentPlayerId();
           //根据ID获取玩家对象
           {   //处理回调函数，返回包装后的回调函数
               Action<List<int>> warppedCallback=selected=>
               {
                   if(selected!=null||selected.Count>0)
                   {
                       Console.WriteLine("玩家取消选择或选择为空");
                   }
                   callback(selected);
               };   
                 //最终调用胡牌UI
            player.GetPlayer(currentPlayerId).ShowHuToUi(currentPlayerId,options,warppedCallback);
           }
       }     
    
    

    public void UpdateGameScene(int playerId, List<int> handCard, List<int> discardCard)
    {
        // 更新游戏界面
    }
    


    public void GameEndHandling(Dictionary<int, int> finalScores,int winningPlayerId )
    {
        // 保存最终得分
        logic.CalculateFinalScores();
        
        // 显示游戏结束界面
        ShowGameEndScene(finalScores);
        
        // 清理资源
        ResetGameData();
    }

    private void ShowGameEndScene(Dictionary<int, int> finalScores)
    {
        // 显示游戏结束界面给所有玩家
        foreach (var playerScore in finalScores)
        {
            /*调用playerui*/
           /* PlayerUI ui = GetPlayerUI(playerScore.Key);*/
            // ui.ShowGameEndScene(playerScore.Key, playerScore.Value);
        }
    }

    // 重置游戏数据
     public void ResetGameData()
    {
        Console.WriteLine("Resetting game data.");
        logic.ResetGameData();
        currentPlayerId = 0;
        currentStatus = GameStatus.Preparing;
    }


    //玩家信息存储完成后的处理
    private void PlayerInformationStored(Dictionary<int, string> playerInfo)
    {
        Console.WriteLine("Player information stored.");
        //通知Logic在data中更新玩家信息
        logic.UpdatePlayerInformation(currentPlayerId,playerInfo);
        // 请求加载游戏大厅界面
        baseLogic.LoadLobbySceneRequested();
    }

    // 玩家输入完成后的处理
    private void PlayerInputComplete()
    {
        Console.WriteLine("Player input completed.");
        // 检查玩家输入是否完整
        bool isInputComplete = baseLogic.CheckPlayerInputCompleteness(baseLogic.GetPlayerInput());
        if (isInputComplete)
        {
            StartGame();
        }
        else
        {
            // 如果输入不完整，提示玩家重新输入
            Console.WriteLine("Player input is incomplete. Please try again.");
            baseLogic.LoadLobbySceneRequested();
        }
    }




}


}




